package com.supporter.sysbench;

import com.supporter.sysbench.result.Statistics;
import com.supporter.sysbench.work.SQLExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xunaidong
 * @date 2021/8/8
 */
@Configuration
public class SysbenchConfiguration {
    @Autowired
    private GlobalProperties globalProperties;
    @Bean(destroyMethod = "destroy")
    public ThreadPoolContext threadPoolContext(){
        return new ThreadPoolContext(globalProperties);
    }
    @Bean(destroyMethod = "destroy")
    public ConnectionPoolContext connectionPoolContext(){
        return new ConnectionPoolContext(globalProperties);
    }
    @Bean
    public Statistics statistics(){
        return new Statistics(globalProperties.getDuration());
    }
    @Bean
    public SQLExecutor sqlExecutor(Statistics statistics,ConnectionPoolContext connectionPoolContext){
        return new SQLExecutor(statistics,globalProperties.getData().getDsName(),globalProperties.getThreads(),connectionPoolContext);
    }

}
